<?php

/**
 * Subclass for representing a row from the 'statement' table.
 *
 *
 *
 * @package lib.model
 */
class LypoStatement extends BaseLypoStatement
{

	var $respects = null;
	var $date_used = null;
	var $thumbnail = null;
	
	public function getVideoCode(){
		$code = null;
		if($this->getYoutubeCode() && $this->getYoutubeCode()!=''){
			$code = $this->getYoutubeCode();
		} elseif ($this->getVimeoCode() && $this->getVimeoCode()!=''){
			$code = $this->getVimeoCode();
		} elseif ($this->getDailymotionCode() && $this->getDailymotionCode()!=''){
			$code = $this->getDailymotionCode();
		}
		return $code;
	}
	
	public function getVideoType(){
		if($this->getYoutubeCode() && $this->getYoutubeCode()!=''){
			return 'youtube';
		} elseif ($this->getVimeoCode() && $this->getVimeoCode()!=''){
			return 'vimeo';
		} elseif ($this->getDailymotionCode() && $this->getDailymotionCode()!=''){
			return 'dailymotion';
		}
		return null;
	}	
	
	
	public function setRespects($num){
		$this->respects = $num;
	}
	
	public function getRespects(){
		return $this->respects;
	}
	
	public function setDateUsed($date){
		$this->date_used = $date;
	}
	
	public function getDateUsed(){
		return $this->date_used;
	}
	
	public function delete($con = null){
		parent::delete($con);
		$this->removeThumbnail();
	}
	
	
	public function getThumbnailPath(){
		$dir = sfConfig::get('app_uploads_thumbnails');
		$file = sprintf('%s.jpg',$this->getId());
		return $dir.DIRECTORY_SEPARATOR.$file;
	}
	
	public function removeThumbnail(){
		if($this->getThumbnail()){
			if(file_exists($this->getThumbnailPath())){
				unlink($this->getThumbnailPath());
			}else{
				throw new sfException('Thumbnail not found');
			}
		}
	}
	
	public function getThumbnail(){
		if($this->isNew()) return null;
		if(!file_exists($this->getThumbnailPath())) return null;
		return sprintf('/uploads/thumbnails/%s.jpg',$this->getId());
	}

	
}
